package com.hd.pzhwlxt.controller.model6;

import com.hd.pzhwlxt.mapper.BarDateMapper;
import com.hd.pzhwlxt.mapper.GoodsUsedMapper;
import com.hd.pzhwlxt.mapper.MaterialUsedMapper;
import com.hd.pzhwlxt.mapper.OfficeMaterialUsedMapper;
import com.hd.pzhwlxt.pojo.*;
import com.hd.pzhwlxt.service.BusinessAndMoneyService;
import com.hd.pzhwlxt.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;
import java.util.Arrays;
import java.util.List;

/**
 * @create: 2022-09-27 14:55
 * @author: 怀念天空
 * @Description:
 */
@RestController
public class DataAnalysisController {
    @Autowired
    private BusinessAndMoneyService businessAndMoneyService;

    @Autowired
    private OfficeMaterialUsedMapper officeMaterialUsedMapper;

    @Autowired
    private MaterialUsedMapper materialUsedMapper;

    @Autowired
    private GoodsUsedMapper goodsUsedMapper;

    @Autowired
    private BarDateMapper barDateMapper;

    @GetMapping("/pie")
    public Response<Object> getPieInfo(){
        List<BusinessAndMoney> list = businessAndMoneyService.getAllInfo();
        double[] moneys = new double[5];
        for (BusinessAndMoney businessAndMoney : list) {
            moneys[businessAndMoney.getBusinessType()-1] = businessAndMoney.getMoney();
        }
        return Response.createSuccessResponse("查询成功",moneys);
    }

    @GetMapping("/line")
    public Response<Object> getLine(){
        List<OfficeMaterialUsed> officeMaterial = officeMaterialUsedMapper.getAllInfo();
        Date[] dates = new Date[7];
        int[] officeMaterialUsed = new int[7];
        for (int i = 0; i < officeMaterial.size(); i++) {
            dates[i] = officeMaterial.get(6-i).getDate();
            officeMaterialUsed[i] = officeMaterial.get(6-i).getNum();
        }
        int[] materialUsed = new int[7];
        List<MaterialUsed> material = materialUsedMapper.getAllInfo();
        for (int i = 0; i < material.size(); i++) {
            materialUsed[i] = material.get(6-i).getNum();
        }

        int[] goodsUsed = new int[7];
        List<GoodsUsed> goods = goodsUsedMapper.getAllInfo();
        for (int i = 0; i < goods.size(); i++) {
            goodsUsed[i] = goods.get(6-i).getNum();
        }
        List<Object> list = Arrays.asList(dates, officeMaterialUsed,materialUsed, goodsUsed);
        return Response.createSuccessResponse("查询成功",list);
    }

    @GetMapping("/bar")
    public Response<Object> getBarDate(){
        List<BarDate> barDates = barDateMapper.getAllInfo();
        double[] data = new double[12];
        for (BarDate barDate : barDates) {
            data[barDate.getMonth() -1] = barDate.getMoney();
        }
        return Response.createSuccessResponse("查询成功",data);
    }
}
